#ifndef __GuiEvent_h__
#define __GuiEvent_h__
#include "vmsys.h"
#include "Framework.h"
#include "TouchEvent.h"
#include "vmio.h"


#define WIN_TYPE_NORMAL		0x0001









#define MSG_WIN_INIT		0x0001
#define MSG_WIN_SHOW		0x0002
#define MSG_WIN_REFRESH		0x0003
#define MSG_WIN_FREE		0x0004

#define USR_WIN_MSG_BASE	0x0100










#define DM_SUPPORT_CONTROLS_MAX		10

#define DM_BOTTOM_SOFTKEY	0x0020
#define DM_EDITBOX			0x0021
#define DM_IMAGE			0x0022

struct gui_point
{
	VMINT x;
	VMINT y;
	VMINT width;
	VMINT height;
};

struct gui_rect
{
	VMINT left;
	VMINT top;
	VMINT right;
	VMINT bottom;
};

struct common_control_property
{
	struct gui_point p;
	VMINT hctrl;
	VMCHAR ctrl_name[20];
	VMINT ctrl_id;
	VMINT is_focused;
	VMINT is_actived;
	
	void (*DrawStateRelease)(VMINT h);
	void (*DrawStatePress)(VMINT h);
	
	TouchEventHandle touch_event_handle;
};

struct common_window_property
{
	struct gui_point p;
	VMINT hwnd;
	VMCHAR win_name[20];
	VMINT win_id;
	VMINT win_type;
	VMINT is_proc_self;

	FuncPtr win_init;
 	FuncPtr win_show;
 	FuncPtr win_refresh;
 	FuncPtr win_free;
	
 	void (*touch_event)(VMINT t_event, VMINT x, VMINT y);

	void (*win_msg_proc)(VMINT hwnd, VMINT msg_id, VMINT wparam, VMINT lparam);
};

struct list_windows
{
	VMINT hwnd;
	struct list_windows* next;
};

typedef struct
{
	VMINT count_total_controls;
	VMINT record_controls[DM_SUPPORT_CONTROLS_MAX];
}mmi_gui_struct;

enum
{
	GUI_PEN_DOWN = VM_PEN_EVENT_TAP,
	GUI_PEN_MOVE = VM_PEN_EVENT_MOVE,
	GUI_PEN_UP = VM_PEN_EVENT_RELEASE,
	GUI_PEN_LONG_DOWN = VM_PEN_EVENT_LONG_TAP,
	GUI_PEN_DOUBLE_CLICK = VM_PEN_EVENT_DOUBLE_CLICK,
	GUI_PEN_REPEAT = VM_PEN_EVENT_REPEAT,

	GUI_PEN_END
};

extern void GuiEventInit(void);
extern void GuiDrawManager(VMINT iControl, void* pControlProperty);
extern void GuiTouchEventHandle(VMINT tevent, VMINT x, VMINT y);

extern void SetControlFocus(struct common_control_property* control, VMINT flag);
extern VMINT GetControlFocus(struct common_control_property* control);

extern struct list_windows *win_list;

#endif
